package util;

import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
import java.util.GregorianCalendar;

import pojo.Evento;

public class DateComparator implements Comparator<Evento>{
	   
    public int compare(Evento emp1, Evento emp2){
   
        /*
         * parameter are of type Object, so we have to downcast it
         * to Employee objects
         */
        //ricostruiamo la data se evento sett
    	Date emp1Age = null;
    	Date emp2Age = null;
    	if(!emp1.isSettimanale())
    		emp1Age = emp1.getData();        
    	else {
            //Date today = new Date();
    		Calendar gre = GregorianCalendar.getInstance();
            //gre.setTime(today);
            int giorno = Utility.toInt(emp1.getGiorno());
    		gre.set(GregorianCalendar.DAY_OF_WEEK,giorno);
    		gre.setTime(emp1.getOra());
    		emp1Age = gre.getTime();
    	
    	}
    	if(!emp2.isSettimanale())	
    		emp2Age = emp2.getData();
    	else {
            //Date today = new Date();
     		Calendar gre = GregorianCalendar.getInstance();
            //gre.setTime(today);
            int giorno = Utility.toInt(emp2.getGiorno());
     		gre.set(GregorianCalendar.DAY_OF_WEEK,giorno);
     		gre.setTime(emp2.getOra());
     		emp2Age = gre.getTime();   		
    		
    	}
        if(emp1Age.after(emp2Age))
            return 1;
        else if(emp1Age.before(emp2Age))
            return -1;
        else
            return 0;    
    }
   
}
